package com.byteslounge.websockets;

import javax.websocket.Session;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 311633
 * @version 1.0
 * @ClassName:
 * @Description:
 * @date 2017/5/13 10:51
 */
public class SessionCache {
    private static final Map<String, Session> sessionMap = Collections.synchronizedMap(new HashMap<String, Session>());
    private static final Map<String, String> userSessionMap = Collections.synchronizedMap(new HashMap<String, String>());


    public static void put(String sessionId, Session session) {
        sessionMap.put(sessionId, session);
    }

    public static Session get(String empCode) {
        String sessionId = userSessionMap.get(empCode);
        if (sessionId != null && sessionId != "") {
            return sessionMap.get(sessionId);
        }

        return null;
    }

    public static void put(String empCode, String sessionId) {
        userSessionMap.put(empCode, sessionId);
    }

    public static void remove(String sessionId) {
        sessionMap.remove(sessionId);
    }
}
